﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Weazel.Badger.Vhdl.Types
{
  public class TypeConversionResult
  {
    private Type[] conversions;  

    #region Properties
    public Type[] Conversions
    {
      get
      {
 
        return conversions;
      }

      set
      {
        conversions = value;
      }
    }

    public int Depth
    {
      get
      {
        if (conversions == null)
          return 1000; // overwhelming !
        return conversions.Length;
      }
    }
    #endregion

    public TypeConversionResult(Type[] conversions, bool reverse)
    {
      if (conversions == null)
        throw new NullReferenceException();

      this.conversions = conversions;

      if (reverse)
        Array.Reverse(this.conversions);
    }

    public override string ToString()
    {
      StringBuilder str = new StringBuilder();

      str.Append(Depth + "> ");

      foreach (Type t in conversions)
      {
        if (t is ArrayType)
          str.Append(string.Format("{0}({1}) -> ", t.ToString(), ((ArrayType)t).Width));
        else
          str.Append(t.ToString() + " -> ");
      }

      str.Remove(str.Length - 4, 4);

      return str.ToString();
    }
  }
}
